<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="static/css/bootstrap.min.css">
</head>


<body>
    <!-- 给一个容器 -->
    <div class="container">
        <div class="row text-center">
            <h1>学生信息管理系统</h1>
            <hr>

            <a href="index.html" class="btn btn-success">首页</a>
            <a href="add.html" class="btn btn-warning">添加</a>

            <br>
            <br>
        </div>


        <div class="row">

            <table id="tb" class="table table-bordered table-condensed table-hover table-responsive text-center">
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>qq邮箱</th>
                </tr>

                <!-- 将result的数据遍历出来 -->


                <!-- <tr>
                        <td>1</td>
                        <td>2</td>
                        <td>3</td>
                        <td>4</td>
                     </tr> -->










            </table>

        </div>
    </div>

</body>

</html>
<script src="./static/js/jquery.min.js"></script>
<script>
    let tb = document.getElementById("tb");
    let str = "";
    // 创建ajax
    let xhr = new XMLHttpRequest();
    // 建立连接
    xhr.open("get", "/index", true);
    // 发送数据
    xhr.send();
    // xhr.onreadystatechange事件
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4){
            if(xhr.status == 200){
                // 渲染数据
                let data = JSON.parse(xhr.response);
                for (var i = 0; i < data.data.length; i++) {
                    str = `<tr>
                            <td>${data.data[i].id}</td>
                            <td>${data.data[i].name}</td>
                            <td>${data.data[i].sex}</td>
                            <td>${data.data[i].age}</td>
                            <td>${data.data[i].qqemail}</td>
                        </tr>`
                    tb.innerHTML += str
                }
            }
        }
    }

</script>